package com.geekchique.runningbuddy.activity;


import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.Menu.Item;
import android.widget.Button;
import android.widget.TextView;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.controller.DayOfJogDetailsControllerImpl;
import com.geekchique.runningbuddy.controller.IDayOfJogDetailsController;
import com.geekchique.runningbuddy.controller.IOptionsMenu;
import com.geekchique.runningbuddy.controller.OptionsMenuImpl;
import com.geekchique.runningbuddy.model.ListOfJogs;
import com.geekchique.runningbuddy.view.dayofjogdetails.JogsListAdapter;


public class Today extends ListActivity {

	private IDayOfJogDetailsController dayOfJogDetailsController;
	private IOptionsMenu optionsMenu;
	ListOfJogs allJogsRanToday;

	@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.today);
		optionsMenu = new OptionsMenuImpl(this);
		dayOfJogDetailsController = new DayOfJogDetailsControllerImpl(this);
        
        allJogsRanToday = dayOfJogDetailsController.getTodaysJogs();
        
        showLastJogDetailsAndTotals(allJogsRanToday);
        
        listAlljogsRunToday(allJogsRanToday);
    }

	private void showLastJogDetailsAndTotals(ListOfJogs allJogsRanToday) {

		dayOfJogDetailsController.createTodayView( 
				this,
				(Button) findViewById(R.id.goto_journal),
				(TextView) findViewById(R.id.miles),
				(TextView) findViewById(R.id.day_total_time),
				allJogsRanToday);
	}

	private void listAlljogsRunToday(ListOfJogs jogEntries) {
		
		if (jogEntries.size() > 0) {
			listAllJogsRanTodayDetails(jogEntries);
		}
		
	}

	private void listAllJogsRanTodayDetails(ListOfJogs jogEntries) {
//		long longOfTimeRun = entry.getStopTime() - entry.getStartTime();
        setListAdapter(new JogsListAdapter(this, jogEntries));
	}
	
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		optionsMenu.selectItem(item);
	    return super.onOptionsItemSelected(item);
	}


}
